package com.shuai.baibi.mq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.shuai.baibi.constant.BIMQConstant;
import lombok.extern.slf4j.Slf4j;


@Slf4j
public class InitBIMQMain {
    public static void main(String[] args) {
        ConnectionFactory connectionFactory = new ConnectionFactory();  // 创建连接工厂
        connectionFactory.setHost("120.46.57.47");  // 设置rabbitmq主机地址
        connectionFactory.setPort(5672);
//        connectionFactory.setUsername("admin");
//        connectionFactory.setPassword("BXS@0518..abc");
        try {
            // 创建链接
            Connection connection = connectionFactory.newConnection();
            // 创建通道
            Channel channel = connection.createChannel();
            // 声明直接交换机
            channel.exchangeDeclare(BIMQConstant.BI_MQ_EXCHANGE_NAME, "direct");
            // 声明消息队列（支持队列消息持久化、队列非独占、非自动删除、额外参数为null）
            channel.queueDeclare(BIMQConstant.BI_QUEUE_NAME, true, false, false, null);
            // 绑定队列到交换机
            channel.queueBind(BIMQConstant.BI_QUEUE_NAME, BIMQConstant.BI_MQ_EXCHANGE_NAME, BIMQConstant.BI_ROUTING_KEY);
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    }
}
